package com.yunji.news.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunji.news.entity.SystemConfig;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 系统配置Mapper接口
 *
 * @author yunji
 * @since 2024-11-25
 */
@Mapper
public interface SystemConfigMapper extends BaseMapper<SystemConfig> {

    /**
     * 根据配置键查询配置值
     *
     * @param configKey 配置键
     * @return 配置值
     */
    @Select("SELECT config_value FROM system_configs WHERE config_key = #{configKey} AND status = 1 AND deleted = 0")
    String selectValueByKey(@Param("configKey") String configKey);

    /**
     * 根据配置分组查询配置列表
     *
     * @param configGroup 配置分组
     * @return 配置列表
     */
    @Select("SELECT * FROM system_configs WHERE config_group = #{configGroup} AND status = 1 AND deleted = 0 ORDER BY sort_order")
    List<SystemConfig> selectByGroup(@Param("configGroup") String configGroup);

    /**
     * 查询所有配置分组
     *
     * @return 配置分组列表
     */
    @Select("SELECT DISTINCT config_group FROM system_configs WHERE status = 1 AND deleted = 0 AND config_group IS NOT NULL ORDER BY config_group")
    List<String> selectGroups();
}